package com.hiyee.api.config;

import com.hiyee.api.interceptors.AdminTokenInterceptor;
import com.hiyee.api.interceptors.PassportInterceptor;
import com.hiyee.api.interceptors.UserActiveInterceptor;
import com.hiyee.api.interceptors.UserTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 *
 * @author WangBin
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public PassportInterceptor passportInterceptor() {
        return new PassportInterceptor();
    }

    @Bean
    public UserTokenInterceptor userTokenInterceptor() {
        return new UserTokenInterceptor();
    }

    @Bean
    public UserActiveInterceptor userActiveInterceptor() {
        return new UserActiveInterceptor();
    }

    @Bean
    public AdminTokenInterceptor adminTokenInterceptor() {return new AdminTokenInterceptor();}


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 短信验证码限制60秒获取一次
        registry.addInterceptor(passportInterceptor()).addPathPatterns("/passport/getSmsCode");

        // 用户 token 校验
        registry.addInterceptor(userTokenInterceptor())
                .addPathPatterns("/user/getAccountInfo")
                .addPathPatterns("/user/updateUserInfo")
                .addPathPatterns("/file/uploadFace");

        // 用户激活状态校验
        // registry.addInterceptor(userTokenInterceptor())
        //         .addPathPatterns("/user/getAccountInfo");

        // 管理员 token 校验
        registry.addInterceptor(adminTokenInterceptor())
                .addPathPatterns("/admin/getAdminList");
        registry.addInterceptor(adminTokenInterceptor())
                .addPathPatterns("/admin/getAdminList");
    }
}
